package com.xuqi.menucontrol;

import java.util.Random;
import java.util.Stack;

import com.xuqi.DemoActivity;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Process;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.Display;

public class MenuControlIF {

	private static int m_iWinchangeDirection = WinchangeDirection.winchangeDirection_Invalid;
	private static int m_iWinchangeType = WinchangeType.winchangeType_Invalid;
	private static boolean m_bWinscapeLocked = false;
	// MenuControl_MSG_ID
	private static final int MSG_TriggerInfo = 777;
	private static final int MSG_DelayWinchange = 780;
	private static final int MSG_TestTrigger = 779;

	// -----------------------------------------------------------------------------
	public static Activity m_curActivity = null;

	private static boolean m_bSetTriggerListener = false;
	private static OnTriggerListener m_ITriggerListener = null;

	// To push received trigger into the activity thread
	private static final MenuControlHandler m_sMenuControlHandler = new MenuControlHandler();

	// Animation Set
	private static int m_iAnimationID = NSAnimationID.Default;
	// lock of winscape change
	private static boolean m_bInScreenChange = false;
	// -------------------------------for set map
	// info----------------------------------//
	private static boolean m_bIsMapScreenNow = false;

	private static boolean m_bWait_MapDrawDone = false;
	private static long m_lSynID = -1;

	private static boolean m_bBackward = false;
	private static boolean m_bNeedFinish = false;
	private static Activity m_preMapActivity = null;
	private static Class m_cMapActivityClass = null;

	private static Class defaultClass = DemoActivity.class;
	private static int m_iRequestCode = -1;

	private static Stack<NSTriggerInfo> m_stackTriggerInfo = new Stack<NSTriggerInfo>();

	// --------------------------------for engine
	// off------------------------------------//
	private static boolean m_bChargeOffFlg = false;
	private static boolean m_bCradleOffFlg = false;
	private static boolean m_bVoiceWarnFlg = false;

	private static final long TIME_WAIT_ENGINE_OFF_MSG = 60000;

	// --------------------------------------------------------------------------//
	// just for test
	public static void SendTestTrigger(NSTriggerInfo triggerinfo, long delaymillis)
	{
		m_sMenuControlHandler.sendMessageDelayed(m_sMenuControlHandler.obtainMessage(MSG_TestTrigger, triggerinfo), delaymillis);
	}

	private static void __ResetEngineOffFlags()
	{
		m_bVoiceWarnFlg = false;
		m_bChargeOffFlg = false;
		m_bCradleOffFlg = false;
	}

	// --------------------------------------------------------------------------
	public static boolean SendTriggerForScreen(NSTriggerInfo TriggerInfo)
	{

		boolean bRet = true;

		if (m_bInScreenChange == true)
		{
			if (TriggerInfo.m_iTriggerID == NSTriggerID.UIC_MN_TRG_MAP_DRAW_DONE)
			{
				if (m_bWait_MapDrawDone && ((m_lSynID <= TriggerInfo.m_lParam1) || (m_lSynID - TriggerInfo.m_lParam1 > 10000)))
				{
					// Log.i("MenuControl","--wait map draw done and get good Trigger map draw done SyncID["+
					// m_lSynID +"] lparam1["+TriggerInfo.m_lParam1+"]--");
					//m_sMenuControlHandler.removeMessages(MSG_MapDrawDoneTimeout);
					m_sMenuControlHandler.sendMessage(m_sMenuControlHandler.obtainMessage(MSG_TriggerInfo, TriggerInfo));
					// Log.i("MenuControl","----do delay action-------------");
					m_sMenuControlHandler.sendMessage(m_sMenuControlHandler.obtainMessage(MSG_DelayWinchange));

				}
				else
				{
					// Log.i("MenuControl","---MapDrawDone["+TriggerInfo.m_iTriggerID+"] in Screen change,Deny Render-----------");
					// Log.i("MenuControl","----sync Map draw done-----return false");
					bRet = false;
				}
			}
			else
			{
				switch (TriggerInfo.m_iTriggerID) {
				case NSTriggerID.UIC_MN_TRG_GUIDE_ROUTE_INFO_CHANGE:
				case NSTriggerID.UIC_MN_TRG_LOC_FEEDBACK:
				case NSTriggerID.UIC_MN_TRG_Route_Load:
				case NSTriggerID.UIC_MN_TRG_LOC_DEBUG_INFO:
					// filter it when screen changing
					break;
				default:
					// Log.i("MenuControl","----MenuControl Send Trigger["+TriggerInfo.m_iTriggerID+"] to Handlder when screen change-------------");
					m_sMenuControlHandler.sendMessage(m_sMenuControlHandler.obtainMessage(MSG_TriggerInfo, TriggerInfo));
					break;
				}
			}
		}
		else
		{ // not in screen change
			// Log.i("MenuControl","---Send Trigger["+TriggerInfo.m_iTriggerID+"] to Handler Normal------------");
			m_sMenuControlHandler.sendMessage(m_sMenuControlHandler.obtainMessage(MSG_TriggerInfo, TriggerInfo));
		}
		return bRet;
	}

	// Call this function in OnSetMapInfo
	public static void SetSynID(long SynID)
	{
		m_lSynID = SynID;
		m_bWait_MapDrawDone = true;
	}

	public static Activity GetCurActivity()
	{
		return m_curActivity;
	}

	public static void __SetCurActivity(Activity thiz)
	{
		m_curActivity = thiz;
	}

	public static void __ScreenChangeFinished()
	{
		m_bInScreenChange = false;
	}

	public static boolean IsWinscapeLocked()
	{
		return m_bWinscapeLocked;
	}

	public static void LockWinscape(boolean bLock)
	{
		// Log.i("MenuControl","----Lock Screen["+bLock+"]-------------");
		m_bWinscapeLocked = bLock;
	}

	public static void SetWinchangeAnimation(int iAnimaID)
	{
		m_iAnimationID = iAnimaID;
	}

	public static int GetWinchangeDirection()
	{
		return m_iWinchangeDirection;
	}

	public static int GetWinchangeType()
	{
		return m_iWinchangeType;
	}

	public static int GetWinchangeStatus()
	{
		return m_iWinchangeDirection | m_iWinchangeType;
	}

	// search if the activity(Class==cls) exist in the stack
	static public boolean searchWinscape(Class cls)
	{
		return ScreenInfoStack.getScreenInfoStack().HasActivity(cls);
	}

	// Get Top Winscape In Stack
	static public Activity GetPreWinscape()
	{
		return ScreenInfoStack.getScreenInfoStack().currentActivity();
	}

	static public void changeWinscape(Class cls)
	{
		changeWinscape(MenuControlIF.GetCurActivity(),cls);
	}
	// start a new activity,push the current activity to the stack
	static public void changeWinscape(Activity thiz, Class cls)
	{
		if (thiz == null || /* thiz.getClass().equals(cls) || */m_bInScreenChange || m_curActivity != thiz)
		{
			// Log.i("MenuControl","----!!!!deny changeWinscape!!!------------------");
			return;
		}

		Log.i("MenuControl", "--ChangeWinscape Start:[" + thiz + "] to [" + cls + "]");
		m_bInScreenChange = true;
		LockWinscape(true);
		m_iWinchangeDirection = WinchangeDirection.winchangeDirection_Forword;
		m_iWinchangeType = WinchangeType.winchangeType_Winchange;

		__RemoveTriggerListener();

		// Log.i("MenuControl","---changeWinscape Push Stack-------------------------------.");
		Intent intent = new Intent();
		intent.setClass(thiz, cls);
		thiz.startActivity(intent);
		__PlayWinscapeChangeAnimation(thiz);
		ScreenInfoStack.getScreenInfoStack().pushActivity(thiz);
		Log.i("MenuControl", "---ChangeWinscape End:[" + thiz + "] to [" + cls + "]");
		__PrintScreenInfoStack();

	}

	static public void changeWinscape(Activity thiz, Class cls, int iRequestCode)
	{
		if (thiz == null || /* thiz.getClass().equals(cls) || */m_bInScreenChange || m_curActivity != thiz)
		{
			// Log.i("MenuControl","---!!!!deny changeWinscape!!!------------------");
			return;
		}

		Log.i("MenuControl", "---ChangeWinscape Start:[" + thiz + "] to [" + cls + "]");
		m_bInScreenChange = true;
		LockWinscape(true);
		m_iWinchangeDirection = WinchangeDirection.winchangeDirection_Forword;
		m_iWinchangeType = WinchangeType.winchangeType_Winchange;

		__RemoveTriggerListener();
		// m_bInScreenChange = false;
		// System.out.println("MenuControl::-----changeWinscape Push Stack-------------------------------.");
		Intent intent = new Intent();
		intent.setClass(thiz, cls);
		thiz.startActivityForResult(intent, iRequestCode);
		__PlayWinscapeChangeAnimation(thiz);
		ScreenInfoStack.getScreenInfoStack().pushActivity(thiz);
		Log.i("MenuControl", "---ChangeWinscape End:[" + thiz + "] to [" + cls + "]");
		__PrintScreenInfoStack();

	}

	// change to a new activity (bNeedFinish to check if need finish current
	// activity)
	static public void changeWinscape(Activity thiz, Class cls, boolean bNeedFinish)
	{
		if (thiz == null || /* thiz.getClass().equals(cls)|| */m_bInScreenChange || m_curActivity != thiz)
		{
			// System.out.println("MenuControl::-----!!!!deny changeWinscape!!!------------------");
			return;
		}

		Log.i("MenuControl", "---ChangeWinscape Start:[" + thiz + "] to [" + cls + "]");
		m_bInScreenChange = true;
		LockWinscape(true);
		m_iWinchangeDirection = WinchangeDirection.winchangeDirection_Forword;
		if (bNeedFinish == true)
		{
			m_iWinchangeType = WinchangeType.winchangeType_KeepStep;
		}
		else
		{
			m_iWinchangeType = WinchangeType.winchangeType_Winchange;
		}

		__RemoveTriggerListener();

		// m_bInScreenChange = false;
		Intent intent = new Intent();
		intent.setClass(thiz, cls);
		thiz.startActivity(intent);
		__PlayWinscapeChangeAnimation(thiz);
		if (bNeedFinish == true)
		{
			// System.out.println("MenuControl::***ChangeWinscape  finish self-------------------------------.");
			thiz.finish();
		}
		else
		{
			// System.out.println("MenuControl::***ChangeWinscape  Push Stack-------------------------------.");
			ScreenInfoStack.getScreenInfoStack().pushActivity(thiz);
		}
		Log.i("MenuControl", "---ChangeWinscape End:[" + thiz + "] to [" + cls + "]");
		__PrintScreenInfoStack();

	}

	static public void ForwardDefaultWinchange(Activity thiz)
	{
		// Clean all the activity in Stack
		if (thiz == null || m_bInScreenChange || m_curActivity != thiz)
		{
			// System.out.println("MenuControl::-----!!!!Deny ForwardDefaultWinchange!!!--------------");
			return;
		}

		Log.i("MenuControl", "---ForwardDefaultWinchange Start From[" + thiz + "]");
		ScreenInfoStack.getScreenInfoStack().popAllActivity();

		m_bInScreenChange = true;
		LockWinscape(true);
		m_iWinchangeDirection = WinchangeDirection.winchangeDirection_Forword;
		m_iWinchangeType = WinchangeType.winchangeType_DefaultWinchange;

		__RemoveTriggerListener();

		Log.i("MenuControl", "---ForwardDefaultWinchange not wait map---------------------------");
		Intent intent = new Intent();
		intent.setClass(thiz, defaultClass);
		thiz.startActivity(intent);
		__PlayWinscapeChangeAnimation(thiz);
		thiz.finish();
		Log.i("MenuControl", "---ForwardDefaultWinchange End From[" + thiz + "]");
		__PrintScreenInfoStack();

	}

	// Back to the unfinished pre-activity
	static public void Backward(Activity thiz)
	{
		if (thiz == null || m_bInScreenChange || m_curActivity != thiz)
		{
			// System.out.println("MenuControl::-----!!!!Deny Backward no destination!!!--------------");
			return;
		}

		Log.i("MenuControl", "---Backward Start From[" + thiz + "]");
		m_bInScreenChange = true;
		LockWinscape(true);

		m_iWinchangeDirection = WinchangeDirection.winchangeDirection_Back;
		m_iWinchangeType = WinchangeType.winchangeType_Winchange;

		if (null == ScreenInfoStack.getScreenInfoStack().currentActivity())
		{
			Log.i("MenuControl", "-----!!!Empty stack!!!Finish last activity-------------");
			thiz.finish();
			m_bInScreenChange = false;
			LockWinscape(false);
			Log.i("MenuControl", "---Backward End From[" + thiz + "]");
			__PrintScreenInfoStack();
			return;
		}

		__RemoveTriggerListener();

		// m_bInScreenChange = false;
		Log.i("MenuControl", "-----Backward no destination--------------");
		thiz.finish();
		__PlayWinscapeChangeAnimation(thiz);
		ScreenInfoStack.getScreenInfoStack().popActivityNoFinish();
		Log.i("MenuControl", "---Backward End From[" + thiz + "]");
		__PrintScreenInfoStack();
	}

	// Back to the Activity (class==cls)
	// if not exist in the stack,start a new activity (class==cls)
	static public void Backward(Activity thiz, Class cls)
	{
		if (thiz == null || m_bInScreenChange || m_curActivity != thiz)
		{
			// System.out.println("MenuControl::-----!!!!Deny Backward with destination!!!--------------");
			return;
		}

		if (ScreenInfoStack.getScreenInfoStack().HasActivity(cls) == false)
		{
			Log.i("MenuControl", "---Backward End Error:Failed to Find Dst-----");
			return;
		}

		Log.i("MenuControl", "---Backward Start From[" + thiz + "] to [" + cls + "]");

		m_bInScreenChange = true;
		LockWinscape(true);
		__RemoveTriggerListener();
		m_iWinchangeDirection = WinchangeDirection.winchangeDirection_Back;
		m_iWinchangeType = WinchangeType.winchangeType_SearchWinchange;

		// m_bInScreenChange = false;
		Log.i("MenuControl", "------Backward with destination--------------");
		ScreenInfoStack.getScreenInfoStack().popAllActivityUntilOne(cls);
		thiz.finish();
		__PlayWinscapeChangeAnimation(thiz);
		Log.i("MenuControl", "---Backward End From[" + thiz + "] to [" + cls + "]");
		__PrintScreenInfoStack();

	}

	public static void __DelayForward()
	{
		if (false == m_bInScreenChange || null == m_preMapActivity || null == m_cMapActivityClass)
			return; // already finished
		// m_bInScreenChange = false;

		Log.i("MenuControl", "-----Do Delay Change Winscape-------------");
		if (m_iRequestCode == -1)
		{
			m_preMapActivity.startActivity(new Intent().setClass(m_preMapActivity, m_cMapActivityClass));
		}
		else
		{
			m_preMapActivity.startActivityForResult(new Intent().setClass(m_preMapActivity, m_cMapActivityClass), m_iRequestCode);
		}
		__PlayWinscapeChangeAnimation(m_preMapActivity);
		if (m_bNeedFinish == true)
		{
			m_preMapActivity.finish();
		}
		else
		{
			ScreenInfoStack.getScreenInfoStack().pushActivity(m_preMapActivity);
		}
		Log.i("MenuControl", "---ChangeWinscape Delay End[" + m_preMapActivity + "] to [" + m_cMapActivityClass + "]");
		m_bBackward = false;
		m_bNeedFinish = false;
		m_preMapActivity = null;
		m_cMapActivityClass = null;
		m_iRequestCode = -1;
		__PrintScreenInfoStack();
	}

	public static void __DelayBackward()
	{
		if (false == m_bInScreenChange || null == m_preMapActivity)
			return; // already finished

		// m_bInScreenChange = false;
		Log.i("MenuControl", "-----Delay Backward-------------");
		if (m_cMapActivityClass == null)
		{
			m_preMapActivity.finish();
			__PlayWinscapeChangeAnimation(m_preMapActivity);
			ScreenInfoStack.getScreenInfoStack().popActivityNoFinish();
		}
		else
		{
			ScreenInfoStack.getScreenInfoStack().popAllActivityUntilOne(m_cMapActivityClass);
			m_preMapActivity.finish();
			__PlayWinscapeChangeAnimation(m_preMapActivity);
		}
		Log.i("MenuControl", "---Backward Delay End[" + m_preMapActivity + "] to [" + m_cMapActivityClass + "]");
		m_bBackward = false;
		m_bNeedFinish = false;
		m_preMapActivity = null;
		m_cMapActivityClass = null;
		__PrintScreenInfoStack();
	}

	// private static MenuControlHandler __DelayCreateMenuControlHandler()
	// {
	// if(m_sMenuControlHandler == null)
	// m_sMenuControlHandler = new MenuControlHandler();
	// return m_sMenuControlHandler;
	// }

	public static void __ResetSynID()
	{
		m_lSynID = -1;
		m_bWait_MapDrawDone = false;
	}

	private static void __PlayWinscapeChangeAnimation(Activity thiz)
	{
		int animaitonID = m_iAnimationID;
		// if(m_iAnimationID == NSAnimationID.Default){
		// Random random = new Random();
		// animaitonID = Math.abs(random.nextInt()%
		// NSAnimationID.Animation_Count);
		// }else{
		// animaitonID = m_iAnimationID;
		// }

		switch (animaitonID) {
		case NSAnimationID.Zoom:
			thiz.overridePendingTransition(com.xuqi.R.anim.zoom_enter, com.xuqi.R.anim.zoom_exit);
			// Animation.playScreenChangeAnimation(thiz,
			// com.carrozzeria.navi.R.anim.zoom_enter,
			// com.carrozzeria.navi.R.anim.zoom_exit);
			break;
		case NSAnimationID.Fade:
			thiz.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
			// Animation.playScreenChangeAnimation(thiz, android.R.anim.fade_in,
			// android.R.anim.fade_out);
			break;
		case NSAnimationID.Slide_Horizontal_L2R:
			thiz.overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.fade_out);
			// Animation.playScreenChangeAnimation(thiz,
			// android.R.anim.slide_in_left, android.R.anim.fade_out);
			break;
		case NSAnimationID.Slide_Horizontal_R2L:
			thiz.overridePendingTransition(com.xuqi.R.anim.slide_in_right, android.R.anim.fade_out);
			// Animation.playScreenChangeAnimation(thiz,
			// com.carrozzeria.navi.R.anim.slide_in_right,
			// android.R.anim.fade_out);
			thiz.overridePendingTransition(com.xuqi.R.anim.slide_in_right, com.xuqi.R.anim.slide_out_left);
			break;
		case NSAnimationID.Slide_Vertical_T2B:
			thiz.overridePendingTransition(com.xuqi.R.anim.slide_in_top, android.R.anim.fade_out);
			// Animation.playScreenChangeAnimation(thiz,
			// com.carrozzeria.navi.R.anim.slide_in_top,
			// android.R.anim.fade_out);
			thiz.overridePendingTransition(com.xuqi.R.anim.slide_in_top, com.xuqi.R.anim.slide_out_bottom);
			break;
		case NSAnimationID.Slide_Vertical_B2T:
			thiz.overridePendingTransition(com.xuqi.R.anim.slide_in_bottom, android.R.anim.fade_out);
			// Animation.playScreenChangeAnimation(thiz,
			// com.carrozzeria.navi.R.anim.slide_in_bottom,
			// android.R.anim.fade_out);
			thiz.overridePendingTransition(com.xuqi.R.anim.slide_in_bottom, com.xuqi.R.anim.slide_out_top);
			break;
		case NSAnimationID.Menu2Menu_Slide_R2L:
			// Animation.playScreenChangeAnimation(thiz,
			// com.carrozzeria.navi.R.anim.slide_in_right,com.carrozzeria.navi.R.anim.slide_out_left);
			break;
		case NSAnimationID.Menu2Menu_Slide_L2R:
			// Animation.playScreenChangeAnimation(thiz,
			// com.carrozzeria.navi.R.anim.slide_in_left,com.carrozzeria.navi.R.anim.slide_out_right);
			break;
		case NSAnimationID.Map2Menu_Slide_B2T:
			// Animation.playScreenChangeAnimation(thiz,
			// com.carrozzeria.navi.R.anim.slide_in_bottom,
			// com.carrozzeria.navi.R.anim.none);
			break;
		case NSAnimationID.Menu2Map_Slide_T2B:
			// Animation.playScreenChangeAnimation(thiz,
			// com.carrozzeria.navi.R.anim.none,
			// com.carrozzeria.navi.R.anim.slide_out_bottom);
			break;
		case NSAnimationID.Default:
		default:
			break;
		}

		m_iAnimationID = NSAnimationID.Default;
	}

	private static void __PrintScreenInfoStack()
	{
		ScreenInfoStack.getScreenInfoStack().LogoutStack();
	}

	// ------------------add or remove Trigger Listener-----------------
	public static void AddTriggerListener(OnTriggerListener listener)
	{
		// System.out.println("MenuControl::-----Try Add Trigger Listener by user:"+listener);
		if (m_bInScreenChange == true)
		{
			// System.out.println("MenuControl::-----!!!Deny Add Trigger Listenner!!!Winscape is Changing!!-------------");
			return;
		}

		m_ITriggerListener = listener;
		m_bSetTriggerListener = true;

		// System.out.println("MenuControl::-----Add Trigger Listener success");

		while (!m_stackTriggerInfo.empty())
		{
			// Post Trigger in the stack to the MainHandler
			// System.out.println("MenuControl::------post Trigger["+
			// i.m_iTriggerID+"] in stack to Handler----" );
			NSTriggerInfo cTrigger = m_stackTriggerInfo.pop();
			cTrigger.m_bDelayed = true;
			m_sMenuControlHandler.sendMessageAtFrontOfQueue(m_sMenuControlHandler.obtainMessage(MSG_TriggerInfo, cTrigger));
		}
	}

	public static void RemoveTriggerListener(OnTriggerListener listener)
	{
		// System.out.println("MenuControl::-----Try remove Trigger Listener by user:"+listener);
		if (m_bInScreenChange == true)
		{
			// System.out.println("MenuControl::-----!!!Deny remove Trigger Listenner!!!Winscape is Changing!!!!!!Already Removed internal!!--------------");
			return;
		}

		if (m_ITriggerListener == listener)
		{
			m_bSetTriggerListener = false;
			m_ITriggerListener = null;
			// System.out.println("MenuControl::-------Remove TriggerListener Success-------");
		}
		else
		{
			// System.out.println("MenuControl::-------Try remove Trigger Listener Failed: No Listener to remove-------");
		}
	}

	private static void __RemoveTriggerListener()
	{
		// System.out.println("MenuControl::-----Trigger Listener removed internal-------------");
		m_bSetTriggerListener = false;
		m_ITriggerListener = null;

		m_stackTriggerInfo.clear();
	}

	public static void handleMessage(Message msg)
	{

		if (true == m_bInScreenChange)
		{
			// This message will be remove when got Good MapDrawDone Event
			Log.i("MenuControl", "-----!!!Warning!!!wait map draw done timeout-------------");
			if (m_bBackward == false)
			{
				__DelayForward();
			}
			else
			{
				__DelayBackward();
			}
			__ResetSynID();
		}

		if (msg.what == MSG_TriggerInfo)
		{
			NSTriggerInfo TriggerInfo = (NSTriggerInfo) msg.obj;
			if (m_bSetTriggerListener == true && m_ITriggerListener != null)
			{
				// Do OnTrigger
				m_ITriggerListener.OnTrigger(TriggerInfo);
			}
			else
			{
				m_stackTriggerInfo.push(TriggerInfo);
			}
		}

		// if(msg.what == MSG_TestTrigger){
		// NSTriggerInfo info =(NSTriggerInfo)msg.obj;
		// //Log.i("MenuControl","---Test Trigger Disabled!!----" +
		// info.m_iTriggerID );
		// }

		if (msg.what == MSG_DelayWinchange)
		{
			if (m_bBackward == false)
			{
				__DelayForward();
			}
			else
			{
				__DelayBackward();
			}
			__ResetSynID();
		}
	}

	public static void notifyScreenSizeChange(Activity context)
	{
		Display disp = context.getWindowManager().getDefaultDisplay();
		int screenWidth = disp.getWidth();
		int screenHeight = disp.getHeight();
		disp = null;
		if (screenWidth > screenHeight)
		{

		}
		else
		{

		}
	}

}

class MenuControlHandler extends Handler {
	public MenuControlHandler() {
		super(Looper.getMainLooper());
	}

	public void handleMessage(Message msg)
	{
		MenuControlIF.handleMessage(msg);
	}
}
